unit UnfmAbreBancoDeDados;

interface

uses
 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
 Dialogs, ExtCtrls, StdCtrls, Buttons, IniFiles;

type
 TfmAbreBancoDeDados = class(TForm)
  lbInfo: TLabel;
  Image1: TImage;
  Edit1: TEdit;
  Label3: TLabel;
  SpeedButton1: TSpeedButton;
  btOK: TBitBtn;
  btCancelar: TBitBtn;
  Bevel1: TBevel;
  OpenDialog1: TOpenDialog;
  procedure btCancelarClick(Sender: TObject);
  procedure btOKClick(Sender: TObject);
  procedure SpeedButton1Click(Sender: TObject);
  procedure FormCreate(Sender: TObject);
  procedure FormKeyPress(Sender: TObject; var Key: Char);
  procedure FormShow(Sender: TObject);
 private
    { Private declarations }
 public
    { Public declarations }
 end;
 
var
 fmAbreBancoDeDados: TfmAbreBancoDeDados;
 PastaAtual: string;
 IniFile: TIniFile;
const
 INI_FILE = 'GTRCalendario.ini';
 
implementation

uses unDM;


{$R *.dfm}

procedure TfmAbreBancoDeDados.btCancelarClick(Sender: TObject);
begin
 Application.Terminate;
end;

procedure TfmAbreBancoDeDados.btOKClick(Sender: TObject);
begin
 if FileExists(edit1.Text) then
  begin
   IniFile.WriteString('BancoDeDados', 'Caminho', edit1.text);
  end
 else
  fmAbreBancoDeDados.ModalResult := mrNone;
end;

procedure TfmAbreBancoDeDados.SpeedButton1Click(Sender: TObject);
begin
 if OpenDialog1.Execute then
  Edit1.Text := OpenDialog1.FileName;
end;

procedure TfmAbreBancoDeDados.FormCreate(Sender: TObject);
begin
 IniFile := TIniFile.Create(ExtractFilePath(Application.ExeName) + INI_FILE);
end;

procedure TfmAbreBancoDeDados.FormKeyPress(Sender: TObject; var Key: Char);
begin
 if key = #27 then
  btCancelar.Click();
end;

procedure TfmAbreBancoDeDados.FormShow(Sender: TObject);
begin
 Edit1.Text := IniFile.ReadString('BancoDeDados', 'Caminho', '');
end;

end.

